//
//  oldActivityAppointmentViewController.m
//  laonianbang
//
//  Created by 勇拓 李 on 18/4/3.
//  Copyright © 2018年 zaiyou. All rights reserved.
//

#import "oldActivityAppointmentViewController.h"
#import "oldActivityDetailViewController.h"
#import "oldFamilyParentListTableViewController.h"

@interface oldActivityAppointmentViewController ()
@property (weak, nonatomic) IBOutlet UILabel *label_title;
@property (weak, nonatomic) IBOutlet UILabel *label_fee;
@property (weak, nonatomic) IBOutlet UILabel *label_time;
@property (weak, nonatomic) IBOutlet UILabel *label_address;
@property (weak, nonatomic) IBOutlet UILabel *label_owner;
@property (weak, nonatomic) IBOutlet UILabel *label_mobile;
@property (weak, nonatomic) IBOutlet UIButton *btn_commit;
@property (weak, nonatomic) IBOutlet UIView *view_chooseParents;
@property (weak, nonatomic) IBOutlet UILabel *label_chooseParents;

@end

@implementation oldActivityAppointmentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [self initData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setParent:(oldServer *)parent
{
    _parent = parent;
    _label_chooseParents.text = parent.uname;
}

#pragma mark - initView
- (void)initView
{
    self.navigationItem.title = @"活动预约";
    
    _btn_commit.layer.cornerRadius = 8.f;
    [_btn_commit addTarget:self action:@selector(btn_commit_tapped) forControlEvents:UIControlEventTouchDown];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoChooseParents:)];
    [_view_chooseParents addGestureRecognizer:tap];
}

- (void)gotoChooseParents:(id)sender
{
    oldFamilyParentListTableViewController *vc = [oldFamilyParentListTableViewController new];
    vc.ifComeFromOrder = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)btn_commit_tapped
{
    if(!_parent.uid)
    {
        [oldHub warningUser:@"请先选择预约的老年人"];
        return;
    }
    
    [oldHub waiting:@"预约中"];
    
    WeakSelf
    
    [OLDNetWork httpRequestWithPostPut:URL_Activity_join params:@{@"aid" : _activity.aid , @"uid" : _parent.uid} success:^(id data) {
        [oldHub hideHUD];
        [oldHub warningUserAfterJump:@"预约成功" time:1.f];
        
        UIViewController *vc = weakSelf.navigationController.viewControllers[[weakSelf.navigationController.viewControllers count] - 2];
        
        if ([vc isKindOfClass:[oldActivityDetailViewController class]]) {
            oldActivityDetailViewController *oldVc = (oldActivityDetailViewController *)vc;
            oldVc.activity.isJoin = @"true";
        }
        [weakSelf.navigationController popViewControllerAnimated:YES];
        
    } error:^(NSString *error) {
        [oldHub warningUser:error];
    }];
}

#pragma mark - initData
- (void)initData
{
    _label_title.text = _activity.title;
    _label_fee.text = [_activity getFeeByPeople];
    _label_time.text = _activity.startTime;
    _label_owner.text = _activity.owner;
    _label_mobile.text = _activity.phone;
    _label_address.text = _activity.address;
}

@end
